package com.jucai.pppeiyouclient.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.utils.SharedPreferencesUtil;
import com.jucai.pppeiyouclient.view.activity.MessageActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

import cn.jpush.android.api.JPushInterface;

import static com.jucai.pppeiyouclient.utils.CrashHandler.TAG;

/**
 * Created by Kuky on 2017-05-10.
 */

public class JPushRegistrationReceiver extends BroadcastReceiver {
    private static final String TAG = "JPushRegistrationReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
            SharedPreferencesUtil.saveStringPreference(context, "J_PUSH", "reg_id", regId);
        }else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            LogUtils.d(TAG + "[CustomJpushReceiver] 用户点击打开了通知");
            //打开自定义的Activity
            Intent i = new Intent(context, MessageActivity.class);
            i.putExtra("jpush_system_msg",2);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
            context.startActivity(i);

        }
    }

}
